import { defineStore } from 'pinia';

interface StoreProps {
  token: string | null;
  userId: string | null;
  wxOpenId: string | null;
}

interface ActionProps {
  setToken: (token: string) => void;
  setUserId: (userId: string) => void;
  setWxOpenId: (wxOpenId: string) => void;
}

export const useUserStore = defineStore<string, StoreProps, any, ActionProps>(
  'userStore',
  {
    state: () => ({ 
      token:localStorage.getItem("token"),
      userId:localStorage.getItem("customerId"), 
      wxOpenId: null,
    }),
    actions: {
      setToken(token: string) {
        this.token = token;
      },
      setUserId(userId: string) {
        this.userId = userId;
      },
      setWxOpenId(wxOpenId: string) {
        console.log(888)
        this.wxOpenId = wxOpenId;
      },
    },
  }
);